package org.creavi.engine.hud;

import java.io.IOException;

import com.jme.math.Vector2f;
import com.jme.util.export.InputCapsule;
import com.jme.util.export.JMEExporter;
import com.jme.util.export.JMEImporter;
import com.jme.util.export.OutputCapsule;
import com.jme.util.export.Savable;

public class HudDefinition implements Savable {
	private String textura;

	private Vector2f uv1;

	private Vector2f uv2;
	
	private float scale;
	
	public HudDefinition() {
		
	}

	public String getTextura() {
		return textura;
	}

	public void setTextura(String textura) {
		this.textura = textura;
	}

	public Vector2f getUv1() {
		return uv1;
	}

	public void setUv1(Vector2f uv1) {
		this.uv1 = uv1;
	}

	public Vector2f getUv2() {
		return uv2;
	}

	public void setUv2(Vector2f uv2) {
		this.uv2 = uv2;
	}

	public float getScale() {
		return scale;
	}

	public void setScale(float scale) {
		this.scale = scale;
	}

	public Class<?> getClassTag() {
		return getClass();
	}

	public void read(JMEImporter im) throws IOException {
		InputCapsule ic = im.getCapsule(this);
		textura = ic.readString("textura", null);
		uv1 = (Vector2f)ic.readSavable("uv1", new Vector2f());
		uv2 = (Vector2f)ic.readSavable("uv2", new Vector2f());
		scale = ic.readFloat("scale", 0);
	}

	public void write(JMEExporter ex) throws IOException {
		OutputCapsule oc = ex.getCapsule(this);
		oc.write(textura, "textura", null);
		oc.write(uv1, "uv1", null);
		oc.write(uv2, "uv2", null);
		oc.write(scale, "scale", 0);
	}
	
	public float getWidth() {
		return (uv2.x - uv1.x) * scale;
	}
	
	public float getHeight() {
		return (uv1.y - uv2.y) * scale;
	}
}
